package com.chenghao.myviewgroup;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.laocaixw.layout.SuspendButtonLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

    private ListView mylistview;
    private Myadapter myadapter;
    private List<String> list;

    private SuspendButtonLayout mySuspendButtonLayout;

    //小球事件 git地址：https://github.com/laocaixw/SuspendButtonLayout

    //左右滑动事件 git地址：https://github.com/louiewh/SwipeMenuLayout


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mySuspendButtonLayout= (SuspendButtonLayout) findViewById(R.id.mySuspendButtonLayout);
        mySuspendButtonLayout.setOnSuspendListener(new SuspendButtonLayout.OnSuspendListener() {
            @Override
            public void onButtonStatusChanged(int status) {
                Log.i("chenghao","onButtonStatusChanged="+status);
            }

            @Override
            public void onChildButtonClick(int index) {
                Log.i("chenghao","onChildButtonClick="+index);
                Toast.makeText(MainActivity.this,"点击了："+index,Toast.LENGTH_SHORT).show();
            }
        });
        mylistview= (ListView) findViewById(R.id.mylistview);
        list=new ArrayList<>();
        for(int c=0;c<50;c++){
            list.add("现在的条目是："+c);
        }

        myadapter=new Myadapter();
        mylistview.setAdapter(myadapter);

    }

    public  class Myadapter extends BaseAdapter{

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView=getLayoutInflater().inflate(R.layout.item,null);
            TextView content= (TextView) convertView.findViewById(R.id.content);
            content.setText(list.get(position));
            Button btnTop= (Button) convertView.findViewById(R.id.btnTop);
            Button btnUnRead= (Button) convertView.findViewById(R.id.btnUnRead);
            Button btnDelete= (Button) convertView.findViewById(R.id.btnDelete);
            btnTop.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"点击了置顶的功能",Toast.LENGTH_SHORT).show();
                }
            });
            btnUnRead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"点击了已读的功能",Toast.LENGTH_SHORT).show();
                }
            });
            btnDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"点击了删除的功能",Toast.LENGTH_SHORT).show();
                }
            });
            content.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"点击了条目",Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(MainActivity.this,AnimActivity.class);
                    startActivity(intent);
                }
            });
            return convertView;
        }
    }
}
